package com.wxdc.nmgyt.nmgytwydc.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.esri.android.map.MapView;
import com.wxdc.nmgyt.nmgytwydc.IMapFunInterface.IMapFunInterface;
import com.wxdc.nmgyt.nmgytwydc.R;

/**
 * Created by Administrator on 2018/3/20.
 * Arcgis在线地图
 */

public class OnlineArcgisMapFragment extends Fragment {

    public static final String TAG_URL = "tag_url";
    private final String  TAG = this.getClass().getSimpleName();
    private MapView mMapView;
    public static OnlineArcgisMapFragment newInstance(Bundle bundle) {
        OnlineArcgisMapFragment fragment = new OnlineArcgisMapFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i(TAG, "onCreate: ------url:"+TAG_URL);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_arcgismap, container, false);
        Toolbar toolbar = view.findViewById(R.id.toolbar);
        setHasOptionsMenu(true);
        ((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
        ((AppCompatActivity)getActivity()).getSupportActionBar().setTitle("");
        TextView titleBarTxt = view.findViewById(R.id.toolbar_title);
        titleBarTxt.setText(R.string.main_toolbar_title_onlinemap);

        mMapView = view.findViewById(R.id.online_mapview);
        mMapView.setEsriLogoVisible(false);
        return view;
    }
    /*
    * 添加菜单
    * */

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        menu.clear();
        inflater.inflate(R.menu.arcgis_online_fragment_menu,menu);
        super.onCreateOptionsMenu(menu, inflater);
    }
    /*
    * 菜单选中事件*/

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int selectID = item.getItemId();
        switch (selectID) {
         /*   case R.id.af_online_submenu_item_bdmap:
                if (getActivity() instanceof IMapFunInterface) {
                    ((IMapFunInterface) getActivity()).switchMap("baiduMap");
                }
                break;
            case R.id.af_online_submenu_item_localMap:
                if (getActivity() instanceof IMapFunInterface) {
                    ((IMapFunInterface) getActivity()).switchMap("localArcgisMap");
                }
                break;*/
            default:
                break;
        }

        return super.onOptionsItemSelected(item);
    }
}
